import { HttpClient, HttpParams } from '@angular/common/http';
import { Inject, Injectable, Injector } from '@angular/core';
import { Observable } from 'rxjs';
import { Banner, HotTag, SampleBack, SongSheet } from './data-types/common.types';
import { API_CONFIG, ServicesModule } from './services.module';
import { map } from 'rxjs/internal/operators';
import { loginParams } from '../share/wy-ui/wy-layer/wy-layer-login/wy-layer-login.component';
import { Signin, User } from './data-types/member.type';
import * as queryString from 'query-string';

@Injectable({
  providedIn: ServicesModule
})
export class MemberService {

  constructor(private http:HttpClient, @Inject(API_CONFIG) private uri:string ) { }
  // 登录
  login(formValue: loginParams): Observable<User>{
    const params = new HttpParams({ fromString: queryString.stringify(formValue) })
    return this.http.get(this.uri + 'login/cellphone',{ params })
    .pipe(map((res:any) => res as User));
  }
  // 获取用户详情
  getUserDetail(uid: string): Observable<User>{
    const params = new HttpParams({ fromString: queryString.stringify({ uid }) })
    return this.http.get(this.uri + 'user/detail',{ params })
    .pipe(map((res:any) => res as User));
  }
  // 退出
  logout(): Observable<SampleBack>{
    return this.http.get(this.uri + 'logout')
    .pipe(map((res:any) => res));
  }
  // 签到
  signin(): Observable<Signin>{
    const params = new HttpParams({ fromString: queryString.stringify({ type: 1 }) })
    return this.http.get(this.uri + 'daily_signin',{ params })
    .pipe(map((res:any) => res as Signin));
  }
}
